#include "btform.h"
#include "ui_btform.h"

btForm::btForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btForm)
{
    ui->setupUi(this);
    line1Animal = new QPropertyAnimation(ui->line_1, "geometry", this);
    line1Animal->setDuration(1500);
    line1Animal->setKeyValueAt(0, QRect(0, 15, 2, 0));
    line1Animal->setKeyValueAt(0.5, QRect(0, 0, 2, 15));
    line1Animal->setKeyValueAt(1, QRect(0, 15, 2, 0));
    line1Animal->setLoopCount(-1);
    //line1Animal->start();
    // 设置line2的动画效果
    line2Animal = new QPropertyAnimation(ui->line_2, "geometry", this);
    line2Animal->setDuration(1600);
    line2Animal->setKeyValueAt(0, QRect(7, 15, 2, 0));
    line2Animal->setKeyValueAt(0.5, QRect(7, 0, 2, 15));
    line2Animal->setKeyValueAt(1, QRect(7, 15, 2, 0));
    line2Animal->setLoopCount(-1);
   // line2Animal->start();
    // 设置line3的动画效果
    line3Animal = new QPropertyAnimation(ui->line_3, "geometry", this);
    line3Animal->setDuration(1700);
    line3Animal->setKeyValueAt(0, QRect(14, 15, 2, 0));
    line3Animal->setKeyValueAt(0.5, QRect(14, 0, 2, 15));
    line3Animal->setKeyValueAt(1, QRect(14, 15, 2, 0));
    line3Animal->setLoopCount(-1);
    //line3Animal->start();
    // 设置line4的动画效果
    line4Animal = new QPropertyAnimation(ui->line_4, "geometry", this);
    line4Animal->setDuration(1800);
    line4Animal->setKeyValueAt(0, QRect(21, 15, 2, 0));
    line4Animal->setKeyValueAt(0.5, QRect(21, 0, 2, 15));
    line4Animal->setKeyValueAt(1, QRect(21, 15, 2, 0));

    line4Animal->setLoopCount(-1);
    //line4Animal->start();
}

btForm::~btForm()
{
    delete ui;
}

void btForm::seticon(QString btIcon, QString btText, int mid)
{
    // 设置⾃定义按钮的图⽚、⽂字、以及id
    ui->btlcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(btText);
    this->id = mid;
}

void btForm::clearBg()
{
    ui->btStyle->setStyleSheet("#btStyle:hover{ background:#D8D8D8;} ");
    ui->btlcon->setStyleSheet("#btlcon:hover{ background:#D8D8D8;} ");
    ui->btText->setStyleSheet("#btText:hover{ background:#D8D8D8;} ");
    ui->lineBox->setStyleSheet("#lineBox:hover{ background:#D8D8D8;} ");
}

int btForm::getId()
{
    return id;
}

void btForm::showAnimal()
{
    line1Animal->start();
    line2Animal->start();
    line3Animal->start();
    line4Animal->start();
}
void btForm::stopAnimal(){
    line1Animal->pause();
    line2Animal->pause();
    line3Animal->pause();
    line4Animal->pause();
}

void btForm::mousePressEvent(QMouseEvent *event)
{
    // 告诉编译器不要触发警告
    (void)event;
    // ⿏标点击之后，背景变为绿⾊，⽂字变为⽩⾊
    ui->btStyle->setStyleSheet("#btStyle{ background:rgb(30,206,154);}*{color:#F6F6F6;}");
    ui->btlcon->setStyleSheet("#btlcon{ background:rgb(30,206,154);}*{color:#F6F6F6;}");
    ui->btText->setStyleSheet("#btText{ background:rgb(30,206,154);}*{color:#F6F6F6;}");
    ui->lineBox->setStyleSheet("#lineBox{ background:rgb(30,206,154);}*{color:#F6F6F6;}");
    this->showAnimal();
    emit btClick(this->id); // 发送⿏标点击信号
}
